package cn.edu.scau.dropship.controller;

import cn.edu.scau.dropship.entity.Classification;
import cn.edu.scau.dropship.service.ClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/classification")
public class ClassificationController {
    @Autowired
    private ClassificationService classificationService;

    @PostMapping(value = "/getAllClassification")
    @ResponseBody
    public List<Classification> getAllClassification() {
        List<Classification> list = classificationService.selectAll();
        System.out.println(list.toString());
        return list;
    }

    @PostMapping("/selectClassificationByID")
    @ResponseBody
    public Classification selectClassificationByID(Integer id) {
        return classificationService.selectByPrimaryKey(id);
    }

    public Classification selectByName(String name) {
        return classificationService.selectByName(name);
    }


    @PostMapping("/selectClassificationNameByID")
    @ResponseBody
    public String selectClassificationNameByID(Integer id) {
        Classification classification=classificationService.selectByPrimaryKey(id);
        return classification.getName();
    }

}
